package pl.grabar.clinic.client.web.actions.identity;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import pl.grabar.clinic.core.dao.Dao;
import pl.grabar.clinic.core.domain.person.User;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

@Action("authenticate")
@InterceptorRef("grabarStack")
@Results({@Result(name = "success", type = "redirectAction", location = "/", params = {"namespace", "/"}),
		@Result(name = "input", location = "authenticate.jsp")})
public class AuthenticateAction extends ActionSupport implements Preparable {

	private static final long serialVersionUID = -8444260653073982413L;

	private static final Log LOG = LogFactory.getLog(AuthenticateAction.class);

	@Autowired
	private Dao<User> userDao;

	private User user;

	private User existingUser;

	@Override
	public void prepare() throws Exception {
	}

	@Override
	public void validate() {
		if (!hasErrors()) {
		}
	}

	@Override
	public String execute() {
//		User u = new User();
//		u.setLogin(user.getLogin());
//		u.setPassword(SecurityServiceUtils.encryptPassword(user.getPassword()));
//		u.setOrganizationContext(organization.getContextId());
//		existingUser = userDao.findByLoginAndPasswordForOrganization(u);

//		if (existingUser == null) {
//			addActionError(getText("pl.xs.xdms.client.web.security.actions.authenticate.incorrect-login-data"));
//			LOG.error("Blad walidacji w trakcie autentykacji. Bledne dane do logowania lub nie ma uzytkownika o podanym loginie:"
//					+ u.getLogin());
//			user = null;
//			return INPUT;
//		}

		return SUCCESS;
	}


}
